package acwing._2LanQiao._3Math_DP;

import java.util.Scanner;

/**
 * @Project : ProgrammingExercises
 * @Package : ACWing._2LanQiao._3Math_DP
 * @File : Q1205.java
 * @Author : WangRuoyu
 * @Date : 2023/3/14 15:15
 */

// dp
public class Q1205 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int p = scan.nextInt();
        int q = scan.nextInt();
        long[] f = new long[p * q + 1];
        f[p] = 1;
        f[q] = 1;
        f[0] = 1;

        for (int i = 0; i < f.length; ++i) {
            if (i >= p) {
                f[i] += f[i - p];
            }
            if (i >= q) {
                f[i] += f[i - q];
            }
        }

        for (int i = f.length - 1; i >= 0; i--) {
            if (f[i] == 0) {
                System.out.println(i);
                return;
            }
        }
    }
}

// 数学规律
//public class Q1205 {
//    public static void main(String[] args) {
//        Scanner scan = new Scanner(System.in);
//        int p = scan.nextInt();
//        int q = scan.nextInt();
//        System.out.println(p * q - p - q);
//    }
//}
